# load pretty jupyter's magics
%load_ext pretty_jupyter
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.model_selection import train_test_split,cross_val_score,cross_val_predict
from sklearn.metrics import roc_curve,roc_auc_score
from sklearn.svm import SVC
pd.set_option('display.max_colwidth', None)
Data exploration and preprocess¶
suicide = pd.read_csv('./Suicide_Detection.csv',usecols=['text','class'])
suicide.head()
suicide[['class']].value_counts()
class non-suicide 116037 suicide 116037 Name: count, dtype: int64
sample_suicide = suicide.iloc[:5000]#We will limit the dataset to first 5,000 for faster computing
sample_suicide.shape
sample_suicide[['class']].value_counts()#Label variable seems to be balanced
class non-suicide 2531 suicide 2469 Name: count, dtype: int64
sample_suicide['class'] = np.where(sample_suicide['class']=='suicide',1,0)#Converting label to numeric where suicide=1 non-suicide=0
sample_suicide.isna().sum()#check for missing; No missing
text 0 class 0 dtype: int64
sample_suicide['text'].duplicated().sum()#Check for duplicated text; No duplicated test
np.int64(0)
len(sample_suicide[sample_suicide['text']==''])#No empty text
0
Set labels and Features
# Labels
y = sample_suicide['class']
# Features
X = sample_suicide.drop('class',axis=1)
Split dataset into train and test
X_train, X_test, y_train, y_test = train_test_split(X,y, test_size=.2,random_state=42)
from sklearn.pipeline import Pipeline
from sklearn.naive_bayes import MultinomialNB, ComplementNB,GaussianNB
from sklearn.ensemble import RandomForestClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.svm import LinearSVC
from sklearn.metrics import accuracy_score,classification_report
Initialize TF-IDF vectorizer, fit, and transform text
vectorizer = TfidfVectorizer()
X_train_vectorized = vectorizer.fit_transform(X_train['text'])
Model Selection & Training¶
Model Training¶
GaussianNB¶
gnb_clf = GaussianNB()
print(cross_val_score(gnb_clf,X_train_vectorized.toarray(),y_train,cv=3))
y_probas_gnb = cross_val_predict(gnb_clf,X_train_vectorized.toarray(),y_train,cv=3,method='predict_proba')
y_scores_gnb = y_probas_gnb[:,1]
[0.73688156 0.74268567 0.73218305]
ComplementNB¶
cnb_clf = ComplementNB()
cnb_clf.fit(X_train_vectorized,y_train)
print(cross_val_score(cnb_clf,X_train_vectorized,y_train,cv=3))
y_probas_cnb = cross_val_predict(cnb_clf,X_train_vectorized,y_train,cv=3,method='predict_proba')
y_scores_cnb = y_probas_cnb[:,1]
[0.69865067 0.69542386 0.71942986]
MultinomialNB¶
mnb_clf = MultinomialNB()
mnb_clf.fit(X_train_vectorized,y_train)
print(cross_val_score(mnb_clf,X_train_vectorized,y_train,cv=3))
y_probas_mnb = cross_val_predict(mnb_clf,X_train_vectorized,y_train,cv=3,method='predict_proba')
y_scores_mnb = y_probas_mnb[:,1]
[0.69865067 0.69617404 0.72093023]
RandomForestClassifier¶
rf_clf = RandomForestClassifier(random_state=42)
print(cross_val_score(rf_clf,X_train_vectorized,y_train,cv=3))
y_probas_rf = cross_val_predict(rf_clf,X_train_vectorized,y_train,cv=3,method="predict_proba")
y_scores_rf = y_probas_rf[:,1]
[0.83208396 0.85371343 0.86346587]
KNeighborsClassifier¶
knn_clf = KNeighborsClassifier()
print(cross_val_score(knn_clf,X_train_vectorized,y_train,cv=3))
y_probas_knn = cross_val_predict(knn_clf,X_train_vectorized,y_train,cv=3,method='predict_proba')
y_scores_knn = y_probas_knn[:,1]
[0.71814093 0.77869467 0.79144786]
LinearSVC¶
svc_clf = LinearSVC()
print(cross_val_score(svc_clf,X_train_vectorized,y_train,cv=3))
y_scores_svc = cross_val_predict(svc_clf,X_train_vectorized,y_train,cv=3,method='decision_function')
[0.89205397 0.90247562 0.90397599]
Model Evaluation on the Training Set¶
model_pred_dict = {
'GNB':y_scores_gnb,
'CNB':y_scores_cnb,
'MNB':y_scores_mnb,
'RF':y_scores_rf,
'KNN':y_scores_knn,
'SVC':y_scores_svc
}
fpr_gnb,tpr_gnb,thresholds_gnb = roc_curve(y_train,y_scores_gnb)
fpr_cnb,tpr_cnb,thresholds_cnb = roc_curve(y_train,y_scores_cnb)
fpr_mnb,tpr_mnb,thresholds_mnb = roc_curve(y_train,y_scores_mnb)
fpr_rf,tpr_rf,thresholds_rf = roc_curve(y_train,y_scores_rf)
fpr_knn,tpr_knn,thresholds_knn = roc_curve(y_train,y_scores_knn)
fpr_svc,tpr_svc,thresholds_svc = roc_curve(y_train,y_scores_svc)
ROC curve¶
def plot_roc_curve():
#plt.plot(fpr,tpr,linewidth=2,label=label)
plt.plot([0,1],[0,1],'k--')
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.0])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate (Recall)')
plt.title('ROC Curve for Suicide Classification')
model_color_dict = {
'GNB':'red',
'CNB':'blue',
'MNB':'green',
'RF':'yellow',
'KNN':'brown',
'SVC':'purple'
}
plot_roc_curve()
for model_name, y_pred in model_pred_dict.items():
fpr_gnb,tpr_gnb,thresholds_gnb = roc_curve(y_train,y_pred)
plt.plot(fpr_gnb,tpr_gnb,color = model_color_dict[model_name],label=model_name)
plt.legend(loc='lower right')
plt.show()
ROC scores¶
print('ROC AUC scores:')
for model_name, y_pred in model_pred_dict.items():
print(f'{model_name}: {roc_auc_score(y_train,y_pred):.3f}')
ROC AUC scores: GNB: 0.738 CNB: 0.950 MNB: 0.950 RF: 0.923 KNN: 0.843 SVC: 0.960
Classification Report¶
model_dict = {
'GNB':gnb_clf,
'CNB':cnb_clf,
'MNB':mnb_clf,
'RF':rf_clf,
'KNN':knn_clf,
'SVC':svc_clf
}
for model_name,model in model_dict.items():
print(model_name)
if model_name=='GNB':
y_pred = cross_val_predict(model,X_train_vectorized.toarray(),y_train,cv=3)
else:
y_pred = cross_val_predict(model,X_train_vectorized,y_train,cv=3)
print(classification_report(y_train,y_pred))
GNB
precision recall f1-score support
0 0.79 0.64 0.71 2011
1 0.70 0.83 0.76 1989
accuracy 0.74 4000
macro avg 0.75 0.74 0.74 4000
weighted avg 0.75 0.74 0.73 4000
CNB
precision recall f1-score support
0 0.97 0.42 0.59 2011
1 0.63 0.99 0.77 1989
accuracy 0.70 4000
macro avg 0.80 0.71 0.68 4000
weighted avg 0.80 0.70 0.68 4000
MNB
precision recall f1-score support
0 0.97 0.43 0.59 2011
1 0.63 0.99 0.77 1989
accuracy 0.71 4000
macro avg 0.80 0.71 0.68 4000
weighted avg 0.80 0.71 0.68 4000
RF
precision recall f1-score support
0 0.83 0.88 0.86 2011
1 0.87 0.82 0.84 1989
accuracy 0.85 4000
macro avg 0.85 0.85 0.85 4000
weighted avg 0.85 0.85 0.85 4000
KNN
precision recall f1-score support
0 0.90 0.59 0.72 2011
1 0.69 0.93 0.80 1989
accuracy 0.76 4000
macro avg 0.80 0.76 0.76 4000
weighted avg 0.80 0.76 0.76 4000
SVC
precision recall f1-score support
0 0.88 0.92 0.90 2011
1 0.92 0.88 0.90 1989
accuracy 0.90 4000
macro avg 0.90 0.90 0.90 4000
weighted avg 0.90 0.90 0.90 4000
Model selection¶
SVC model was selected due to highest ROC AUC, highest Recall, and highest F1 scores.
Error analysis¶
y_train_pred = cross_val_predict(svc_clf,X_train_vectorized,y_train,cv=3)
X_tp = X_train[(y_train == 1) & (y_train_pred == 1)]
X_fn = X_train[(y_train == 1) & (y_train_pred == 0)]
X_fp = X_train[(y_train == 0) & (y_train_pred == 1)]
X_tn = X_train[(y_train == 0) & (y_train_pred == 0)]
False positives¶
X_fp.head()
| text | |
|---|---|
| 191 | Does anyone else feel like they were neglected by their parents just because you were never a problem child? I know this isn't really a thing to complain about, but i've always wondered if anyone else felt the same\n\nI wa thirdborn in my family and homeschooled for the first 10 years. My mother had to school my rwo older brothers before I came into the world and this whittled down my mothers patience. By the time I was needing to be schooled, my mother was already busy enough with my other brothers that she didn't have the capacity to give me very much attention. \n\nBy the time I was able to read well on my own, my mother would just plop a textbook down in front of me and I would go ahead and study on my own. I learned rather quickly that my mother had little patience when I asked for help twice in a row, or took too long to figure out easy stuff. Yelling and occasionally beatings would follow so I stopped asking for help altogether. \n\nFrom that point on, almost everything I did was on my own. I would start to fear help itself so I would kick my rear into overdrive and focus the hell out of my times tables or whatever it was that I was studying just to avoid help altogether. \n\nIt wasn't just with studying. I was for some strange reason really sensetive to yelling and I would prefer a beating rather than a scold on pretty much every occasion. Because of this, I learned cery quickly how to be a good boy in the house, not making any trouble whatsoever. Never causing problems and never having any that I had to ask assistance with.\n\nI had fun by myself in those times. Jigsaw puzzles and puzzle books and jacks and whatever other 1 player games I could find, I played them. Keeping all the possible problems I could cause to a minimum.\n\nA decade down the line, i'm now older and in high school. I do exceedingly well in every class and never cause a problem for anybody. I do find myself without a social life which I considered to be a waste of energy at the time. I've also noticed that all my exceptional achievements are going pretty much unseen by my parents. I believe that they just got used to how I was never a problen and now its standard in their eyes. I grew up always being great and pushing into greatness even further is exceedingly difficult.\n\nNow i'm 19 and I feel in sort of trapped in this image I created for my parents that I "must always be perfect" and "never cause a problem". I've worked so hard to keep this image but I feel like its tearing me down.\n\nI feel really down all the time now. I just feel so unmotivated and unhappy. The "good boy" in me says to ignore all that emotional bs and just keep moving along, but its harder and harder to do that every passing day. I just feel depressed. I hide it all from my parents because this would be an issue that I would be putting onto them. "Sorry mom, but your 3rd child has a problem". Also, I don't even know if theyll care.\n\nAnd looking back on this whole situation, I feel like I have only myself to blame. I feel like I was the one who caused my parents to not care about me because I never wanted them to care about me and I avoided it whereever I could.\n\nI'm the one who caused them to look at me the way they do. \n\nDoes anyone else feel the same? |
| 152 | my boyfriend is getting his wisdom teeth removed today so i wanted to make a cute post just raving about him and hopes he sees it but i doubt he will :) Well, he's asleep right now cause he hasn't replied to my messages but he deserves the rest, he'll be sleepy all day. \n\nAnyway...\n\nHe's so amazing. I love him so much, our 4 year anniversary is coming up on February 14. I got him his gift and it's currently in transit. I just wanted to say he's literally the most amazing thing to ever happen to me, I wouldn't be the person I am today without him. I... live in an extremely toxic home, and I hate it, I'm not allowed to date but I don't care, I fell in love with someone, and we've been together almost 4 years now. He's so amazing...He's so kind, and charming, and passionate, and loving, and willing, and handsome and cute and literally any positive thing you can think of. He has no flaws. He's so perfect in my eyes. He's been there for me when literally no-one else has. I couldn't be more thankful. I am so lucky, that everyday I get to call this wonderful human mine, and I get to call him cute everyday. Things have been hard with covid, we've been apart 315 days, which is, to most LDR's silly, but he's my only friend. I...am a pretty lonely person, but that's alright. I have about 2 other close friends and that's all I really need. He's literally my best friend. He's been with me through everything. Like I said, I have a toxic home-life, my father is a POS and my mother...she isn't much better. Before him, I knew there was something mentally wrong with me, and to this day my parents still don't really believe I have an anxiety disorder and I quite possibly could be depressed. (not being dramatic it's rough.) He is also my first, well everything just about. This is the first real-real relationship I've been in, he was my first kiss, my first slow-dance, my first everything. He's so timid and gentle and knows exactly how I'm feeling even if I don't tell him initially. He tells me he's proud of me, and the first time he told me that, I broke down into tears. No one has ever ever told me they were proud of me, he sees the smallest steps I take and he recognizing me for them. I've been working my hardest on not apologizing so often and getting a grasp on my anxiety. I know to some now, it's so silly to think that you're first relationship is the one you're gonna marry. But I so truly believe he'll be the one I marry, I want to get married to him, I want to have a life with him. These past 4 years, I haven't felt sad, like "unneeded" sad, of course I have days, but he's literally lit my life up. I wrote a poem about/for him last year and in the poem, I talk about how he re-lit my "spark". My spark is well myself, my personality, my happiness, my passions my all of it. I don't think I could ever begin to repay him. With everything he's done...I'm overjoyed. And I tell him all of this everyday and he takes it with such modesty, or "I know I'm all these things, but so are you" He knows me, he knows who I am, he's the first person to ever willfully get to know who I am, and to love every, single, inch of me, even the parts I can't love right now.\n\n​\n\nI think I'll stop there for now, I could novels upon novels about my love for him, but I think now is a good time to stop. I'm currently working on a song for him, It's been a really long writing process but I think it's coming along well. Anyway, thanks for reading that whole long winded thing, :) |
| 4354 | am I allowed to be jealous? I mean it's kinda a weird and dumb question to ask, but idk I'm just jealous ig, I mean I'm 16 and my life is so sporadic and uncertain and it's so mentally and emotionally draining, I see my cousins and my uncle's and aunts lives and I wish so much that I could had their lives, all my cousins aren't emotionally scarred and hurt, they all have great lives and great families that aren't broken and shattered into pieces, they have a father that loves them and they don't have to worry about if they are gonna be able to go to the college that they want to go to, they don't have to worry about if they are going to be able to afford a car or health insurance or anything, I'm just so tired of seeing everyone around me having happy and nice lives and then to see my mom and brother and myself just be so emotionally destroyed by my dad and we are always stressed even when we shouldn't have to at that moment, I'm tired of having ptsd of my dad and just not feeling like I'm wanted, I just want a normal life with a normal and happy family where everyone loves each other and there was no pain whatsoever, I'm so tired, why do things have to be like this in my life, most of the time I'm just home alone with my brother being in nyc for college and my mom being at work a lot of the time, it's so hard to be this lonely and to have no one with you that actually understands your pain and struggles |
| 220 | Here's my list of hobbies * Switching between phone and pc. \n* Using the same 3 apps/webpages\n* listening to the same song over and over\n* putting myself in imaginary scenarios that will never happen \n* having a "hi" exchange for weeks in a row\n* getting more and more sad everyday\n* getting more anxious every day\n* wanting to play with my dogs but i can't since there's a malaria outbreak in my city\n* worrying about my mental health\n* worrying about my sexuality\n* asking if my friends actually are my friends.\n* etc and etc\n\n​\n\n^(help) |
| 3381 | Looking for friends(15M) I am feeling very low and need someone to talk to, such situations have happened before and those are like a 1 time thing, I want real friends. Hmu if u want to know more about me |
X_fp['text'].str.len().describe()
count 161.000000 mean 755.459627 std 857.999279 min 25.000000 25% 204.000000 50% 448.000000 75% 991.000000 max 5212.000000 Name: text, dtype: float64
False negatives¶
X_fn.head()
| text | |
|---|---|
| 3802 | I [20M] need help talking to my suicidal friend [20M] \n\nI \[20M\] currently share an apartment with my friend \[20M\], his brother \[20M\] and his girlfriend \[19F\].\n\nMy friend was talking to his girlfriend and I about her needing to find a hobby since she has free time that she doesn't know what to do with. She mentioned that he also needs to find another hobby which I agreed with as he recently and his brother recently dropped out of university (his girlfriend and I still attend) and all he does all day is play video games. I know that video games can be a fine hobby but it takes up his day from the time he wakes up to the time he goes to sleep. When I suggested that they find a hobby that they could do together he rejected the idea. When his girlfriend said that she wasn't fond of him playing video games for around 10-16 hours a day he said that it keeps his mind off of suicide and that she would have to deal with it until he gets better.\n\nHe doesn't go to any counselling that I'm aware of and doesn't leave the house all that often except for things like running to the corner store or the grocery store.\n\nNeither his brother nor his girlfriend are really in great mental places right now either so I'm not sure if they'll be up for having a serious talk with him.\n\nI'm worried about him but I'm not sure what I should do, any advice would be appreciated. |
| 3017 | Anyone who survived an attempt and looking for support?Not sure if this is the right sub. I'd like to get in touch with anyone that have survived an attempt. And talk if its okay. Thanks |
| 205 | I found the location.Next step is to get the rope, and hold off till the date comes |
| 3830 | Unlikely TopicsYou know what's unlikely? An unfunny drag queen. What do you think? |
| 305 | Relatives and suicideI know it's a sensitive topic but i'm interested in what it was like for people which had others in their family or close friend group commit suicide. |
X_fn['text'].str.len().describe()
count 241.000000 mean 333.954357 std 456.490875 min 11.000000 25% 93.000000 50% 195.000000 75% 372.000000 max 3247.000000 Name: text, dtype: float64
True negatives¶
X_tn.head()
| text | |
|---|---|
| 4193 | go ahead, call the cops they can’t unpog you anyways |
| 2968 | What are your ways of procrastinating on computers? I just want to know your ways, something other than the obvious playing games please |
| 4793 | How to know if you have ADHD so basically recently I have been having lots of trouble concentrating on stuff and idk why. I feel like I may have adhd or something because I thinks that’s what it is. Idk if this is adhd or if this is something else, if anyone knows how to tell if you have adhd let me know because idk how to explain to my teachers why I’m not able to finish my work because I cant concentrate. This might be a stupid/useless post but idk |
| 4368 | Do you ever wake up after moving thinking you still live in your old house and you wake up to the neighbors screaming at the top of their lungs in Portuguese and you’re like since when did the Finnegans learn Portuguese. And then it registers that your dad got transferred again and You moved to From the UK to Switzerland again, And the new neighbors are not the Finnegans you aren’t proficient in Portuguese yet so you have no idea what you’re saying plus the fact you’re 11 So outside of the unwelcome wake up call you really don’t give a shit...lol\n\n||||\n|:-|:-|:-|\n|||| |
| 2970 | just learned about Deuteronomy 23:2 wish i knew about it *BEFORE* i stuck my penis into a blender |
X_tn['text'].str.len().describe()
count 1850.000000 mean 290.210811 std 511.301328 min 21.000000 25% 99.000000 50% 159.000000 75% 282.750000 max 12651.000000 Name: text, dtype: float64
True positives¶
X_tp.head()
| text | |
|---|---|
| 4227 | I might kill myself tomorrowLife is just too much. It just seems to be getting worse. I try so hard but nothing gets better! I cant think of anything but hurting myself. I just want to be dead. I cant take it any more. Im so useless, theres no reason for me to keep fighting. |
| 4676 | I dont see things getting much betterClearly, if I'm posting here im not 100% wanting to die. In fact, I really wish life could be better for me. I just dont believe I will get better. My issues come from a lot of trauma, and I've been in therapy for more than 3 years. I consistently do things to try to better my life. I try to make healthier decisions, I try to be a better person, and I try to employ the "fake it til you make it" method of being happy (not in a disingenuous way just trying to make good habits). I have some good days. I have some comfortable and quiet days. I do not necessarily have happy days. And, more so than the former, I have a lot of really hard moments and days. \n\n\nI'm tired of feeling haunted. I'm tired of the hauntings always coming back, and always getting in the way. I feel like I'm doing everything I can, maybe I'm not, i dont know. But at what point is it just the rational decision to accept the reality of circumstance? There are plenty of people trapped to cycles of mindsets and behaviors they cannot change, or are almost incapable of changing. \n\n\nOn my best days, I do not believe in much besides biology and chance. Things have no meaning besides what you give them. If I were capable of feeling safe and comfortable, then I would be happy finding things that I have meaning in. And i try to do this. But I can't have the basic foundation of stability. On my worst days, I am convinced that the world, or at least my own world, is plagued with pain. The one thing I can believe in is pain. It is consistent and promised and not fake. I cannot believe in anything else as genuinely as I can pain. \n\n\nAt what point is limiting the amount of pain I continue to endure or encounter the more rational decision, rather than being a sitting duck waiting for the next trauma to come? Or the next affirmation that I cannot trust myself nor others? Or the next proof that there is no good around me. I dont want to wait for those things. My hauntings convince me those things are coming, whether they are or not. Which makes those things reality anyways. \n\n\nI'm tired of the moments where I feel completely despaired and fearful. Not even entirely sure what my body and mind are dreading most of the time, sometimes my mind just rationalizes that intense fear by creating paranoid thoughts. And then I lose my sense of self and reality even more. It's awful to have flashbacks and nightmares and then paranoia. Its awful to believe everything can and will hurt me. I'm tired. |
| 800 | Scared sister is going to do itMy dad and my sister have never been good friends. Today they started screaming at each other, my sister started swearing (we're Christians) and my dad tried to hit my sister (but I stopped him). She said she couldn't take it anymore and ran to her room. I'm scared out of my life that she's going to kill herself. What do/can I do? |
| 3671 | Leaving for a while?Hi people. So yeah I've been thinking about blowing my head off with a 12 gauge for years now. Well any ways, I've been thinking that I might as well delay such actions and try and do something interesting. I'm thinking about just packing a whole bunch of shit into my car and leaving. Quitting my job, dropping out of school, and just driving somewhere else. Or maybe even leave the country. Thinking about cutting contact with everyone I know. My parents are paying for my college right now and would be pissed about me wasting their money. However, I feel like they would rather have me gone and their money wasted than a dead son. I'm hoping such a trip will allow me to find some satisfaction and enjoyment out of life. Is this a good idea? Have any of you ever tried something similar and perhaps just found out that it is your circumstances or the people you know that make your life miserable? |
| 2776 | Peace out, Good luck.Dear you,\n\nI just wanted someone to know my story.\nSince the suicide note I left my family is far more simple.\nit's more like "soz lads, seya lata dnt 4get ur toilet papur".(kappa)\nOn Wednesday the 06/07/2016 at around 9pm I will be dead, this time I'm jumping off a cliff so it's pretty ensured. (DO A FLIP!)\nBy the pictures it looks like it has a beautiful view.\n\nSo I am a 21 year old female from Australia. \nI'm not pretty or smart, I have no talents nor am I a good person. \nI loved League of Legends, Overwatch, Halo and The Ocarina of the time is the best Zelda game.\nI'm a fucking loser who enjoys listening to shitty music and pretending I'm "one of the boys".\nEven though everyone fucking knows I'm not and I'll never be on their level.\n\nMy reason for finally ending it this time is that I'm too broken to fix. {Insert emo ass music here pft}\nWhen I was about 10 I tried to jump off a balcony knowing that I would die and it'd fix all my problems. I did this because I was tired of being sexually abused, mentally abused and physically abused. I'm in some child porno somewhere on the internet so that shit lasts forever. By physically abused I don't mean "omg my mem hit me for throwing my iphone at someone" I literally mean that my step mother would beat the fuck out of me then bash me even more smashing my head against windows because I would bleed, I still remember the feeling of grabbing the steel grid under my bed and pulling my body so just I wouldnt get beat again for being alive. I don't blame my step mother for her cuntish behaviour, after all she was a kid (like 19) herself when she came to a new country just to have 3 kids shoved in her face, she was probably raised the same way.\n\nMy second attempt was when I was around 14 or 15. My mother moved to America with her new Husband and my father had his new family, so my brother sister and I had no place to go. We moved into an apartment, run only by us children. My brother was a total fucking cunt at that age, and with no parental supervision or guidance all of us were fucked. I probably only went to school a few times that year. I don't know what stopped me from jumping in front of those train tracks, but I ended up at a friends house and they treated me like family it hurt so much. I was probably using them. I didn't expect people noticed I went missing and after my cousin told me that I was a missing person I told him where I was, after all I'm not a real cause for drama and the police losing time over.\n\nMy Third attempt was when I was 18 I tried to swallow a bottle of pills, I had just lost my job in America, a country where I only went to protect my mother who was being abused by some low life fuck only to get kicked out as soon as I turnt 18. I lived in the ghetto. I earned 8.75 an hour for a high stress job, I worked 6 days a week worked from 5am to 7pm with an hour break, I ate mc donalds every fucking day because I had no time. And worst of all I dropped out of university, which I wouldve graduated soon. That is what broke me the most. I always had a plan, I'm going to get into the art industry, go to uni, finish when I was 18 and move to Japan to live in some small shitty apartment in Ikebukuro, and that wouldn't matter because I'd be happy anyway. My body ended up rejecting the amount of pills I had taken and all I did was throw up, pretty picture. That's the closest I came to dying, it was kinda weird, I wasn't attached to my body at all or at least it felt like it. It was almost like I was watching myself die, until I threw up that it. I ended up reaching out to my mum, she said I could move back in with her, only to be told a few days later to go kill myself. That's when I wanted to try again and told my sister goodbye this time, but she told me to come back to Australia and wasted all her money on a plane ticket for my useless ass. I'll never forget that.\n\nI never got to get to my fourth attempt, I had moved in my a friend and her cute family who I was also probably using being the shit I am. They sent me to hospital. I never want to go back.\n\nMy dad is back in my life and he is trying, and I love him so much but it sucks knowing that you're wasting peoples times constantly. It feels so bad. I feel so sorry for him. My mother hates me and I don't blame her she wasted money on bringing me up only to be some fucking useless twat. \nMy sister is nice but she'd be better off without me and my brother hates me it's pretty obvious, I also don't blame him.\n\nOkay so logically, emotions aside I feel like suicide is beneficial to my society.\n(I'm pretty sure playing video games all day isn't helping anyone other than myself.)\nI can't work, properly socialise or preform any activities that help others.\n\nWith out my life: Government doesn't have to pay for me to live, friends don't have to bother with suspecting that I don't like them because I'm bad at communicating and family doesn't have to give a single fuck about a lost cause anymore.\n\nI have a home, I have food, I have a bed, I have internet, I have electricity, I have opportunity for education but what I don't have is the fucking logic to appreciate any of it and stop being a little bitch.\n\nHence why I, just another fucking dead loser have justified my suicide! \nI don't have anyone to tell this to so I guess I'll just leave it here for you to laugh at.\n\nRegardless;\nI wish you all the best in life, and I hope you can be happy.\nI know that there are a bunch of you out there who can actually make it and not pussy out of life like me. \n\nFrom, \nJust another dead person. |
X_tp['text'].str.len().describe()
count 1748.000000 mean 1102.780320 std 1220.164572 min 40.000000 25% 372.750000 50% 717.500000 75% 1389.000000 max 15669.000000 Name: text, dtype: float64
Fine-tuning¶
TfidfVectorizer Fine-tuning¶
Lets try to fine-tune the TfidfVectorizer to see if we get better results. We will try the following parameter combinations:
ngram_range:- (1,1)(default)
- (1,2)
- (1,3)
stop_words:- english
- None(default)
ngram=(1,1); stop_words='english'¶
vectorizer = TfidfVectorizer(ngram_range = (1,3),stop_words='english')
X_train_vectorized_n13_en = vectorizer.fit_transform(X_train['text'])
y_pred_n13_en = cross_val_predict(svc_clf,X_train_vectorized_n13_en,y_train,cv=3)
print(classification_report(y_train,y_pred_n13_en))
precision recall f1-score support
0 0.85 0.93 0.89 2011
1 0.92 0.83 0.88 1989
accuracy 0.88 4000
macro avg 0.89 0.88 0.88 4000
weighted avg 0.89 0.88 0.88 4000
Recall worse then baseline model
ngram=(1,3); stop_words=None¶
vectorizer = TfidfVectorizer(ngram_range = (1,3))
X_train_vectorized_n13 = vectorizer.fit_transform(X_train['text'])
y_pred_n13 = cross_val_predict(svc_clf,X_train_vectorized_n13,y_train,cv=3)
print(classification_report(y_train,y_pred_n13))
precision recall f1-score support
0 0.85 0.93 0.89 2011
1 0.92 0.83 0.87 1989
accuracy 0.88 4000
macro avg 0.88 0.88 0.88 4000
weighted avg 0.88 0.88 0.88 4000
Recall worse then baseline model
ngram=(1,1); stop_words='english'¶
vectorizer = TfidfVectorizer(stop_words='english')
X_train_vectorized_en = vectorizer.fit_transform(X_train['text'])
y_pred_en = cross_val_predict(svc_clf,X_train_vectorized_en,y_train,cv=3)
print(classification_report(y_train,y_pred_en))
precision recall f1-score support
0 0.87 0.93 0.90 2011
1 0.92 0.86 0.89 1989
accuracy 0.90 4000
macro avg 0.90 0.90 0.90 4000
weighted avg 0.90 0.90 0.90 4000
Recall better than baseline model
ngram=(1,2); stop_words='english'¶
vectorizer = TfidfVectorizer(stop_words='english',ngram_range = (1,2))
X_train_vectorized_en = vectorizer.fit_transform(X_train['text'])
y_pred_en = cross_val_predict(svc_clf,X_train_vectorized_en,y_train,cv=3)
print(classification_report(y_train,y_pred_en))
precision recall f1-score support
0 0.86 0.94 0.89 2011
1 0.93 0.84 0.88 1989
accuracy 0.89 4000
macro avg 0.89 0.89 0.89 4000
weighted avg 0.89 0.89 0.89 4000
Recall for non-suicide is better but for suicide group is worse.
ngram=(1,2); stop_words=None¶
vectorizer = TfidfVectorizer(ngram_range = (1,2))
X_train_vectorized_en = vectorizer.fit_transform(X_train['text'])
y_pred_en = cross_val_predict(svc_clf,X_train_vectorized_en,y_train,cv=3)
print(classification_report(y_train,y_pred_en))
precision recall f1-score support
0 0.87 0.93 0.90 2011
1 0.93 0.85 0.89 1989
accuracy 0.89 4000
macro avg 0.90 0.89 0.89 4000
weighted avg 0.90 0.89 0.89 4000
Recall for non-suicide is better but for suicide group is worse.
Evaluate Model on the Test set¶
predictSVC = svc_clf.predict(X_test_vectorized)
print(f'SVC accuracy score: {accuracy_score(y_test,predictSVC):.2f}')
print(f'SVC ROC AUC score: {roc_auc_score(y_test,predictSVC):.2f}')
msg = 'some example post'
pipeSVC.predict([msg])